package com.zhenmyan.secdeal.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhenmyan.secdeal.mapper.OrderMapper;
import com.zhenmyan.secdeal.mapper.SecDealOrderMapper;
import com.zhenmyan.secdeal.pojo.SecDealOrder;
import com.zhenmyan.secdeal.pojo.User;
import com.zhenmyan.secdeal.service.SecDealOrderService;
import org.hibernate.validator.constraints.pl.REGON;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * description:
 *
 * @author 颜真明
 * @date 2023/5/11  6:55
 */
@Service
public class SecDealOrderServiceImpl extends ServiceImpl<SecDealOrderMapper, SecDealOrder> implements SecDealOrderService {

    @Resource
    private SecDealOrderMapper secDealOrderMapper;

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public Long getResult(User user, Long goodsId) {
        if (redisTemplate.hasKey("isStockEmpty:" + goodsId)) {
            return -1L;
        }
        SecDealOrder secDealOrder = secDealOrderMapper.selectOne(new QueryWrapper<SecDealOrder>()
                .eq("user_id", user.getId())
                .eq("goods_id", goodsId));
        if (null != secDealOrder) {
            return secDealOrder.getOrderId();
        } else {
            return 0L;
        }
    }


}
